<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <h1>9.html</h1>
  <button onclick="save()">write</button>
  <button onclick="read()">read</button>
  <script>
    function save() {
      // const expires1 = new Date('2022-04-04').toUTCString();
      const expires1 = new Date(+new Date() + 3000).toUTCString();
      console.log(expires1);
      document.cookie = "username=lili;expires=" + expires1;
      document.cookie = "age=21;max-age=5";
      document.cookie = "gender=boy;max-age=0";
      document.cookie = `${encodeURIComponent('max age')}=20`;
      document.cookie = `${encodeURIComponent("长度")}=200`;
    }
    function read() {
      console.log(document.cookie);
      console.log(decodeURIComponent(document.cookie));
    }
  </script>
</body>

</html>